package com.djy.shxt.nemt.api;

import com.djy.shxt.nemt.domain.ApiResult;
import com.djy.shxt.nemt.enity.SpecialityPost;
import com.djy.shxt.nemt.service.SpecialityPostService;
import com.djy.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;


/**
 * @author daijiyong
 */
@RestController
@RequestMapping(value = "/api/school")
@Api(tags = "测试接口2")
public class SchoolApi {

    private static final Logger log = LoggerFactory.getLogger(SchoolApi.class);

    @Autowired
    SpecialityPostService specialityPostService;

    /**
     * 测试内容
     *
     * @param address 测试内容
     * @return ApiResult
     */
    @GetMapping(value = "/list/address/{address}")
    @ApiOperation(value = "测试内容", response = ApiResult.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "address", value = "测试内容", dataType = "String", required = true),
    })
    public ApiResult getListByAddress(@PathVariable("address") String address) {
        ApiResult apiResult = ApiResult.success("测试内容");
        Set<String> schools = new LinkedHashSet<>();
        log.info(address);
        log.error(specialityPostService.countAll() + "");
        if (StringUtils.isNotEmpty(address)) {
            List<SpecialityPost> specialityPostList = specialityPostService.selectBySchool(address);
            for (SpecialityPost specialityPost : specialityPostList) {
                schools.add(specialityPost.getSchool());
            }
        }
        apiResult.put("schools", schools);
        return apiResult;
    }

}
